import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/recipe/data/api/cook_model_api.dart';
import 'package:casdon/modules/recipe/data/repository/recipe_repository.dart';
import 'package:casdon/modules/recipe/providers/recipe_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class CookModelListUsecase {
  final RecipeRepository _repository;

  const CookModelListUsecase(this._repository);

  Future<List<ResponseCookModelApi>> execute() async {
    try {
      var ret = await _repository.getCookClassesModules();
      return ret ?? [];
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("CookModelListUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("CookModelListUsecase 失败");
    }
  }
}

final cookModelListUsecaseProvider = Provider(
  (ref) => CookModelListUsecase(ref.read(recipeRepository)),
);
